home *** CD-ROM | disk | FTP | other *** search
- /*****
- *
- * Grant's CGI Shell (Common Grant Interface :-)
- * http://arpp.carleton.ca/grant/mac/grantscgi/
- *
- * MyCGIProcess.c
- *
- * Sample application using the cgi interface.
- *
- * CustomCGIProcess is where you will do your application specific processing
- * of the cgi stuff.
- *
- * by Grant Neufeld
- *
- * Copyright ©1995,1996 by Grant Neufeld
- *
- * http://arpp.carleton.ca/grant/
- * gneufeld@ccs.carleton.ca
- * grant@acm.org
- *
- * This source may be freely used as long as the copyright notice is kept in the source.
- * I ask that you let me know of any enhancements (read: bug fixes) to this code.
- * I would also like copies of (or discounts on) anything you produce using this code, please.
- *
- *****/
-
- #include "MyConfiguration.h"
- #if kCompileWithCGICode
-
- #include <string.h>
- #include <Threads.h>
-
- #include "compiler_stuff.h"
- #include "globals.h"
-
- #include "CGI.h"
- #include "DebugUtil.h"
- #include "LogUtil.h"
- #include "MemoryUtil.h"
- #include "ProcessUtil.h"
-
-
- /*** CUSTOM CGI FUNCTION ***/
-
- /* This function is where the CGI is actually processed.
- You should replace its contents with your own.
- You need to allocate (*theCGIHandle)->responseData using MemoryNewHandle.
- Put an HTTP header at the beginning of (*theCGIHandle)->responseData.
- Put your data immediately following the last character of the HTTP header.
- (*theCGIHandle)->responseData will be automatically deallocated by the CGI handler.
- You should set (*theCGIHandle)->responseSize to be the size of the responseData,
- including null terminator if you have one.
-
- (this function's prototype is defined in CGI.h) */
- void
- CustomCGIProcess ( CGIHdl theCGIHandle )
- {
- char * myResponseData;
-
- /* debugging check to ensure that theCGIHandle is not NULL */
- my_assert ( theCGIHandle != NULL,
- "\pCustomCGIProcess: theCGIHandle is NULL" );
-
- (*theCGIHandle)->responseSize = gHTTPHeaderOKSize
- + 142 /* size of my constant string */ + 1 /* null terminator */;
-
- (*theCGIHandle)->responseData = MemoryNewHandle ( (*theCGIHandle)->responseSize, nil );
- if ( (*theCGIHandle)->responseData != NULL )
- {
- /* get a local pointer to the responseData to make things a little easier */
- HLock ( (*theCGIHandle)->responseData );
- myResponseData = *((*theCGIHandle)->responseData);
-
- strcpy ( myResponseData, (char *)gHTTPHeaderOK );
- strcpy ( &(myResponseData[gHTTPHeaderOKSize]),
- "\r<TITLE>Grant's CGI Framework</TITLE>\r<BODY>This framework doesn't do anything. You must add your own code to generate useful results.</BODY>\r" );
-
- HUnlock ( (*theCGIHandle)->responseData );
- }
- else
- {
- (*theCGIHandle)->responseSize = nil;
- }
-
- /* you should try to make use of giving time,
- especially in for and while loops or where you have to wait for
- some other process to return data or finish a task. */
- ProcessGiveTime ( nil );
- } /* CustomCGIProcess */
-
-
- /* this function will be called after the cgi result has been returned.
- It will contain the same CGIHdl that was used for the CustomCGIProcess.
- This function's prototype is defined in "CGI.h" */
- void
- CustomCGIPostProcess ( CGIHdl theCGIHdl )
- {
- /* as an example, I'll log some info here */
- LogStringBreakP ( "\pHere is a post-process log entry:" );
-
- #if kCompileWithCGIfull_request
- /* now I'll try to log the full_request, if it's present */
- if ( (*theCGIHdl)->full_request != NULL && ((*theCGIHdl)->full_request)[nil] != nil )
- {
- LogStringP ( "\p\tfull_request: " );
- LogStringBreak ( (*theCGIHdl)->full_request );
- }
- #endif
- } /* CustomCGIPostProcess */
-
-
- /*** CUSTOM CGI INITIALIZATION ***/
- #pragma segment Startup
-
- /* Put any of the initialization you need done, here.
- This function will be called once: in-between the startup
- sequence and the main event loop.
- Return true if the initialization was successful, otherwise false.
- An initialization failure will result in the application quitting. */
- Boolean
- CustomCGIStartup ( void )
- {
- return true;
- } /* CustomCGIStartup */
-
-
- /*** CUSTOM CGI CLEAN UP ***/
- #pragma segment Main
-
- /* This function is called at quitting time. Put any cleanup you need to do in it.
- Return true if you are succeful.
- Return false if you are unable to quit for some reason (this generally only
- applies when the user cancels)
- allowUserInteract specifies whether you can make user interface calls.
- However, CGIs generally should not rely on any user interface calls, so don't
- depend on them. */
- Boolean
- CustomCGIQuit ( Boolean allowUserInteract )
- {
- return true;
- }/* CustomCGIQuit */
-
-
- #endif /* kCompileWithCGICode */
-
- /*** EOF ***/
-